<?php

namespace app\common\repositories\activity;


use app\common\dao\activity\NewActivityDao;
use app\common\repositories\BaseRepository;
use think\facade\Db;

class NewActivityRepository extends BaseRepository
{
    public function __construct(NewActivityDao $dao)
    {
        $this->dao = $dao;
    }

    /**
     * @param array $where
     * @param $page
     * @param $limit
     * @return array
     * @author Qinii
     */
    public function search(array $where, $page, $limit)
    {
        $query = $this->dao->search($where)->order('create_time DESC');
        $count = $query->count($this->dao->getPk());
        $list = $query->page($page, $limit)->hidden(['update_time'])->select();
        return compact('count', 'list');
    }


    public function getNewActivity($where)
    {
        return $this->dao->search($where)->find();
    }

    /**
     * 根据主键查询
     * @param int $id
     * @param null $except
     * @return bool
     * @author Qinii
     */
    public function exists(int $id, $except = null)
    {
        return $this->dao->fieldExists($this->dao->getPk(), $id, $except);
    }




}
